<?php
include 'conn.php';

header("Content-type: text/html; charset=utf-8");
$smarty = new Smarty;

$html = 'http://weixin.sogou.com/pcindex/pc/pc_2/pc_2.html';

use QL\QueryList;

$rules = array(
    'title' => array('h4 a','text'),
    'url' => array('h4 a','href'),
    'author' => array('li .pos-wxrw a [title]','html'),
    'intro' => array('.wx-news-info2 .wx-news-info','text')
);
$data = QueryList::Query($html,$rules)->data;


foreach ($data as $v => $a)
{
     $ro = $db -> get_results("SELECT * FROM `wx_article` WHERE `title`='$a[title]' and `url`='$a[url]'");
     if (count($ro) == '0'){
         $dateline = time();
         $db -> query("INSERT INTO `wx_article`( `classid`, `title`, `intro`, `author`, `url`, `dateline`) VALUES ('0','$a[title]','$a[intro]','$a[author]','$a[url]','$dateline')");
         }
     }

$rs = $db -> get_results("SELECT * FROM `wx_article` where del='0' order by tid desc");
foreach ($rs as $key => $b){
     $lists[$key]['tid'] = $b -> tid;
     $lists[$key]['title'] = $b -> title;
     $lists[$key]['author'] = $b -> author;
     $lists[$key]['url'] = $b -> url;
     $lists[$key]['intro'] = $b -> intro;
	 $lists[$key]['hits'] = $b -> hits;
     $lists[$key]['time'] = date('Y-m-d h:s',$b -> dateline);
     }


$smarty -> assign("list", $lists);
$smarty -> display("./templates/index.html");
?>